package com.dfbz.demo01_匿名内部类案例回顾;

/**
 * @author lscl
 * @version 1.0
 * @intro:
 */
public class Demo01 {

    public static void main(String[] args) {

        /*
        class Xxx implements Comparator{
            @Override
            public String compare(int num1, int num2) {

                if (num1 > num2) {
                    return "大于";
                } else if (num1 < num2) {
                    return "小于";
                } else {
                    return "等于";
                }
            }
        }

        Comparator c = new Xxx();
        String res = c.compare(20, 20);
        System.out.println(res);


         */
        Comparator c = new Comparator() {
            @Override
            public String compare(int num1, int num2) {

                if (num1 > num2) {
                    return "大于";
                } else if (num1 < num2) {
                    return "小于";
                } else {
                    return "等于";
                }
            }
        };

        String res = c.compare(20, 20);
        System.out.println(res);

    }
    public static void test(String[] args) {

        Comparator c1 = new ComparatorImpl_01();
        String res1 = c1.compare(20, 20);
        System.out.println(res1);
        System.out.println("--------------");

        Comparator c2=new ComparatorImpl_02();
        String res2 = c2.compare(20, 20);
        System.out.println(res2);

    }
}


class ComparatorImpl_02 implements Comparator{
    @Override
    public String compare(int num1, int num2) {

        if(num1> num2){

            return "第一个数大于第二个数啊！^___^";
        }else if(num1<num2){
            return "第一个数小于第二个数啊！^__^";
        }else{
            return "第一个数等于第二个数啊！^_^";
        }
    }
}


class ComparatorImpl_01 implements Comparator {
    @Override
    public String compare(int num1, int num2) {

        if (num1 > num2) {

            return "1";
        } else if (num1 < num2) {
            return "-1";
        } else {
            return "0";
        }
    }
}

interface Comparator {
    String compare(int num1, int num2);
}

